package com.nerve.secondhandcar.controller;

import javax.servlet.http.HttpServletRequest;

import org.ko.core.web.BaseController;
import org.ko.core.web.Result;
import org.ko.core.websupport.log.Log;
import org.ko.core.websupport.log.impl.LogUitls;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nerve.secondhandcar.controller.model.ResaleApplyModel;
import com.nerve.secondhandcar.domain.ResaleApply;
import com.nerve.secondhandcar.service.ResaleApplyService;

/**
 * @project: secondHandCarPlatform
 * @file: ResaleApplyController.java
 * @package: com.nerve.secondhandcar.controller.reception
 * @description:
 *	转售申请
 * @author: 集成显卡	1053214511@qq.com
				IBM GDC, zengxm@cn.ibm.com
 * @date&time: 2014-10-23
 * @change log:
 */
@Controller
@RequestMapping("/car/apply")
public class ResaleApplyController extends BaseController{

	@Autowired
	private ResaleApplyService service;
	
	@Override
	protected String getTemplatePath() {
		return "car/apply/";
	}
	
	/**
	 * 查看实体
	 * @param req
	 * @param model
	 * @param viewMap
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="view")
	public String view(HttpServletRequest req, ResaleApplyModel model, ModelMap viewMap)
		throws Exception {
		service.view(model);
		
		viewMap.addAttribute(ENTITY, model.getBean());
		return view(VIEW);
	}
	
	@RequestMapping(value="list", method=RequestMethod.GET)
	public String list(HttpServletRequest req, ModelMap map, ResaleApplyModel model) throws Exception{
		service.list(model);
		map.addAttribute(PAGINATION, model);
		return view("list");
	}
	
	@Log(message="删除了转售申请",category="Resale")
	@RequestMapping(value="delete")
	public @ResponseBody Result delete(HttpServletRequest req, ModelMap map,
			@RequestParam(value = "ids", required = true)Long id[]){
		Result result = new Result();
		try {
			service.delete(id);
			result.setMessage("操作成功");
		} catch (Exception e) {
			result.error(e);
			LogUitls.error(e);
		}
		return result;
	}
}